package by.grsu.pochebut.initializer;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import by.grsu.pochebut.entity.Admin;
import by.grsu.pochebut.entity.Booking;
import by.grsu.pochebut.entity.Car;
import by.grsu.pochebut.entity.Client;
import by.grsu.pochebut.interf.InterfAdmin;
import by.grsu.pochebut.interf.InterfBooking;
import by.grsu.pochebut.interf.InterfCar;
import by.grsu.pochebut.interf.InterfClient;

import com.epam.grsulab.webapi.dao.base.Dao;
import com.epam.grsulab.webapi.entity.base.BaseEntity;
import com.epam.grsulab.webapi.tools.DataInitialiser;

@Component
public class Initializer implements DataInitialiser {
	private static final Logger logger = LoggerFactory.getLogger(Initializer.class);

	@Autowired
	private InterfClient iclient;
	@Autowired
	private InterfCar icar;
	@Autowired
	private InterfBooking ibooking;
	
	@Autowired
	private InterfAdmin iadmin;
	
	public void initData() {
		logger.info("Starting initializing of objects");
		
		Admin admin=new Admin();
		iadmin.save(admin);
		
		Client client = new Client();
		client.setName("Second");
		client.setPassport("kh4787986");
		iclient.save(client);
		
		Car car = new Car();
		car.setModel("honda");
		car.setPrice(25.7);
		car.setColor("white");
		car.setData();
		icar.save(car);
		
		Booking booking=new Booking();
		booking.setClient(client);
		booking.setCar(car);
		booking.setBill(booking.getCar().getPrice());
		ibooking.save(booking);
		
	}

	public List<Dao<? extends BaseEntity>> getAllDAOs() {
		List<Dao<? extends BaseEntity>> list = new ArrayList<Dao<? extends BaseEntity>>();
		list.add(iclient);
		list.add(icar);
		list.add(ibooking);
		list.add(iadmin);
		return list;
	}

}
